<template>
  <el-form ref="ruleForm" :model="formExpress" :rules="rulesExpress" label-width="80px">
    <el-form-item label="快递公司" prop="company">
      <el-select v-model="formExpress.company" placeholder="请选择快递公司">
        <el-option label="韵达快递" value="yunda"></el-option>
        <el-option label="邮政快递包裹" value="youzhengguonei"></el-option>
        <el-option label="中通快递" value="zhongtong"></el-option>
        <el-option label="圆通速递" value="yuantong"></el-option>
        <el-option label="顺丰速运" value="shunfeng"></el-option>
        <el-option label="百世快递" value="huitongkuaidi"></el-option>
        <el-option label="申通快递" value="shentong"></el-option>
        <el-option label="京东物流" value="jd"></el-option>
        <el-option label="EMS" value="ems"></el-option>
        <el-option label="天天快递" value="tiantian"></el-option>
        <el-option label="德邦" value="debangwuliu"></el-option>
        <el-option label="宅急送" value="zhaijisong"></el-option>
        <el-option label="优速快递" value="youshuwuliu"></el-option>
        <el-option label="德邦快递" value="debangkuaidi"></el-option>
        <el-option label="百世快运" value="baishiwuliu"></el-option>
        <el-option label="品骏快递" value="pjbest"></el-option>
        <el-option label="TransRush" value="transrush"></el-option>
        <el-option label="DHL-中国件" value="dhl"></el-option>
        <el-option label="中通快运" value="zhongtongkuaiyun"></el-option>
        <el-option label="安能快运" value="annengwuliu"></el-option>
        <el-option label="速尔快递" value="suer"></el-option>
        <el-option label="苏宁物流" value="suning"></el-option>
        <el-option label="韵达快运" value="yundakuaiyun"></el-option>
        <el-option label="安达速递" value="adapost"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="单号" prop="num">
      <el-input v-model="formExpress.num" placeholder="填写单号"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="expressSubmit">提交</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
  import _ from 'lodash'
  export default {
    name: 'InputLogis',
    data() {
      return {
        formExpress: {
          company: '',
          num: ''
        },
        rulesExpress: {
          company: [
            { required: true, message: '请选择快递公司', trigger: 'blur' }
          ],
          num: [
            { required: true, message: '请输入快递单号', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      expressSubmit: _.throttle(function() {
        this.$refs.ruleForm.validate(async (valid) => {
          if(!valid) {
            return false
          }
          
          let {data: {code, data, msg}} = await this.$axios({
            url: this.$api + '/v1/deliver/expre',
            method: 'post',
            data: {
              com: this.formExpress.company,
              number: this.formExpress.num,
              order: this.$route.params.id
            }
          })
          
          if(code == 0) {
             this.$message.success(data)
             this.$emit('close')
          } else {
            this.$message.warning(msg.message)
          }
        })
      },2000,{
        trailing: false
      })
    }
  }
</script>

<style>
</style>
